public class Ex5_22{
	public static void main(String[] args){
		System.out.printf("%.3f\n", sqrt(4));
	}

	public static double sqrt(double num){
		double lastGuess = 1;
		double nextGuess = (lastGuess + (num/lastGuess)) / 2;
		while (Math.abs(lastGuess-nextGuess) >= 0.0001){
			lastGuess = nextGuess;
			nextGuess = (lastGuess + (num/lastGuess)) / 2;
		}
		return nextGuess;
	}
}